package com.tech.view.component;

import com.tech.view.common.SwingTestUtils;

import javax.swing.*;
import java.awt.*;

/**
 * 透明组件，主要用于给某一区域设置监听事件
 * <p>
 * 典型案例是给含有文本域、按钮的面板Panel添加监听事件，这时候就可以把组件添加到面板中，并且要占满整个面板
 */
public class TransparentComponent extends JComponent {
	private int width;
	private int height;

	public TransparentComponent() {
		init();
	}

	public TransparentComponent(int width, int height) {
		this.width = width;
		this.height = height;

		init();
	}

	public static void main(String[] args) {
		SwingTestUtils.loadSkin();
		SwingTestUtils.test(new TransparentComponent(200, 100));
	}

	private void init() {
		if (width > 0 && height > 0) {
			setPreferredSize(new Dimension(width, height));
		}

		setOpaque(false);
	}

	@Override
	public void paint(Graphics g) {
	}
}
